﻿using System.IO;

namespace Paragon
{
    public static class FileExtension
    {
        public static string Para(this FileInfo source, params object[] parameters)
        {
            FileStream stream = source.Open(FileMode.Open, FileAccess.Read, FileShare.Read);
            StreamReader reader = new StreamReader(stream);

            string text = string.Empty;

            long length = stream.Length;
            int count = 0;
            int sum = 0;
            char[] buffer = new char[1024];

            //reader.Read(

            while ((count = reader.Read(buffer, sum, (int)length - sum)) > 0)
            {
                sum += count;

                text += new string(buffer, 0, count);                
            }

            reader.Close();

            return text.Para(parameters);            
        }

        public static void Para(this FileInfo source, FileInfo destination, params object[] parameters)
        {
            string text = source.Para(parameters);

            StreamWriter writer = destination.CreateText();
            writer.Write(text);
            writer.Flush();
            writer.Close();
        }
    }
}
